<?php
if(preg_match('#' . basename(__FILE__) . '#', $_SERVER['PHP_SELF'])){
	header($_SERVER['HTTP_HOST']);
	exit();
}

	$px_results = $wpdb->get_results("SELECT * FROM ".$px_model->vars['albums']);
?>
<div id="px_message"></div>

<div class="wrap">
	<h2><?php _e("PhotoXhibit Albums", 'photoxhibit'); ?></h2>
    <fieldset class="options">
        <legend><?php _e("Quick Album Edit", 'photoxhibit'); ?></legend>
        <input type="hidden" name="px_albumNameHolder" id="px_albumNameHolder" value=""/>
        <table width="100%" cellspacing="3" cellpadding="3" border="0">
            <tbody>
                <tr>
                    <th align="right"><?php _e("Select album", 'photoxhibit'); ?></th>  
                    <td>
                        <select name="px_albumSelect" id="px_albumSelect">
                            <option value="0"><?php _e("No album selected", 'photoxhibit'); ?></option>
							<?php
                                if($px_results) {
                                    foreach($px_results as $px_result) {
                                        echo '<option id="pxOption'.$px_result->album_id.'" ';
										echo 'value="'.$px_result->album_id.'">';
										echo $px_result->album_name.'</option>';
                                    }
                                }
                            ?>
                        </select>
                    </td> 
                    <th align="right" id="px_addUpdateTxt"><?php _e("Add new album", 'photoxhibit'); ?></th>
                    <td><input value="" name="px_addUpdateInput" id="px_addUpdateInput"/></td>
                    <td class="submit">
                        <input type="submit" 
                            id="px_deleteAlbumBtn" 
                            value="<?php _e("Delete &raquo;", 'photoxhibit'); ?>" 
                            name="px_deleteAlbumBtn" 
                            style="display:none;"/>
                        <input type="submit" 
                            id="px_addUpdateAlbumBtn" 
                            value="<?php _e("Add &raquo;", 'photoxhibit'); ?>" 
                            name="px_addUpdateAlbumBtn"/>
                    </td>
                </tr>
            </tbody>
        </table>
    </fieldset>
    
    <table width="100%"  border="0" cellspacing="3" cellpadding="3" id="px_albumTable">
		<thead>
			<tr class="thead">
				<th width="2%"><?php _e("ID", 'photoxhibit'); ?></th>	
				<th width="85%"><?php _e("Album Title", 'photoxhibit'); ?></th>
				<th><?php _e("Delete", 'photoxhibit'); ?></th>
			</tr>
		</thead>
	<?php
		if($px_results) {
	?>
		<tbody>
		<?php
			$i = 0;
			foreach($px_results as $px_result) {
				if($i%2 == 0) {
					$style = 'style=\'background-color: #eee\'';
				}  else {
					$style = 'style=\'background-color: none\'';
				}
		?>
			<tr <?php echo $style;?> id="pxTrId<?php echo $px_result->album_id;?>">
				<td><?php echo $px_result->album_id;?></td>
				<td><a href="admin.php?page=px_manageAlbum&amp;pxalbum_action=manage_images&amp;aid=<?php echo $px_result->album_id;?>"><?php echo $px_result->album_name;?> (<?php _e("Edit Images", 'photoxhibit'); ?>)</a></td>
				<td><a href="admin.php?page=px_manageAlbum&amp;pxalbum_action=delete_album&amp;aid=<?php echo $px_result->album_id;?>" class="px_optDelete"><?php _e("Delete", 'photoxhibit'); ?></a></td>
			</tr>
		<?php 
				$i++;
			}
		?>
		</tbody>
		<?php
		}
		else{
			echo '<tr><td colspan="7" align="center"><strong>'. __("No Albums Found</strong>", 'photoxhibit') .'</td></tr>';
		}?>
	</table>
    
</div>